/*author dm*/
$(document).ready(function()
{
	$("#account").focus(function(){changCssAttr("#uin_tips","display","none")});
	$("#account").blur(function(){changCssAttr("#uin_tips","display","block",$(this).val()=="")});
	$("#pwd").focus(function(){changCssAttr("#pwd_tips","display","none")});
	$("#pwd").blur(function(){changCssAttr("#pwd_tips","display","block",$(this).val()=="")});
	$("#uin_del").click(function(){clearInputValue("#account");$("#account").blur()});
	$("#login_button").mouseover(function(){changCssAttr(this,"background","url(../img/icon_2.png) no-repeat -116px -90px")});
	$("#login_button").mouseout(function(){changCssAttr(this,"background","url(../img/icon_2.png) no-repeat 0 -90px")});
	$("#login_button").click(function(){submitLoginData()});
});
/*改变一个元素css的一个属性*/
function changCssAttr(element,cssName,cssValue,condition)
{
	if(condition || condition == null)
	{
		$(element).css(cssName,cssValue);
	}
}
/*清空一个输入框的内容*/
function clearInputValue(inputElement)
{
	$(inputElement).val("");
}

function submitLoginData()
{
	
	//check input 学号 to be 13number;
	var acc = $("#account").val();
	
	//acc = "2010231010013";    ///========= ----
	
	if($.isEmptyObject(acc))
	{
		showErrorMsg("学号不能为空");
		return;
	}
	if(!$.isNumeric(acc) || !(acc.length == 13))
	{
		showErrorMsg("学号只能为13位数字");
		return;
	}
	var pwd = $("#pwd").val();
	
	//pwd = "123456";   // / ====== -----
	
	if($.isEmptyObject(pwd))
	{
		showErrorMsg("请输入密码");
		$("#pwd").focus();
		return;	
	}
	//show loading tips
	changCssAttr("#loading_tips","display","block");
	
	var data = 'lgjsn={"sid":"'+acc+'","pwd":"'+pwd+'"}';
	
	$.post("../php/login.php",data,function(data)
	{
		changCssAttr("#loading_tips","display","none");
		data = data.slice(1);
		showErrorMsg(data)
	},"text");
	
}
function showErrorMsg(msg)
{
	$("#err_m").html(msg);
	changCssAttr("#error_tips","display","block");
	$("#error_tips").fadeIn().delay(2000).fadeOut("slow",function()
	{
		changCssAttr("#error_tips","display","none");
	});
}